<?php
namespace AdminBundle\Repository;


class BaseDataSourceRepository extends BaseRepository
{
    public function pageQuery($_params, $page)
    {
        $sql = <<<EOF
select 
    id, name, note, is_enabled as isEnabled, creator, ip, ctime, username, password, token, uri, method, action, param 
from base_data_source 
where 1=1 
EOF;
        $params = array();
        if (!empty($_params)) {
/*            if (isset($_params['starttime'])) {
                $sql .= ' and ctime > :starttime ';
                $params['starttime'] = $_params['starttime'];
            }
            if (isset($_params['endtime'])) {
                $sql .= ' and ctime < :endtime ';
                $params['endtime'] = $_params['endtime'];
            }*/
            if (isset($_params['keyword']) && !empty($_params['keyword'])) {
                $sql .= ' and name like :keyword ';
                $params['keyword'] = '%' . $_params['keyword'] . '%';
            }
        }
        $sql .= ' ORDER BY id DESC';

        return $this->pageWithRawSql($sql, $params, $page);
    }

}
